<template>
  <el-dialog
          title="详情"
          :visible.sync="dialogVisible"
          width="80%"
          :before-close="handleClose"
  >
    <div style="height: 100%" class="workspace">
    <el-container ref="listWarp" style="height: 100%; background-color: #fff">
      <el-header style="display: flex;align-items: center;justify-content: flex-end">
        <ToolButton :disabled="button.disabled" :icon="button.icon" :key="button.text" :left-line="button.leftLine" :right-line="button.rightLine" :text="button.text" :title="button.title" @buttonClick="toolButtonClick" v-for="button in toolButtons" style="margin-top:0;margin-right: 10px;" />
      </el-header>
      <el-main style="height: 100%" class="page-main">
        <div class="content" style="height: calc(100% - 60px)">
          <el-table :data="tableData" height="600px" style="width: 100%" border v-loading="loadIng" :default-sort="{ prop: 'passTime', order: 'descending' }" @sort-change="changeTableSort">
            <el-table-column type="index" width="50"></el-table-column>
            <el-table-column prop="account" label="学号" width="180"></el-table-column>
            <el-table-column prop="name" label="姓名" width="180"></el-table-column>
            <el-table-column prop="collegeName" label="学院" width="200px"></el-table-column>
            <el-table-column prop="className" label="班级"></el-table-column>
            <el-table-column prop="buildingName" label="楼宇" width="200px"></el-table-column>
            <el-table-column prop="roomName" label="房间" width="100px" sortable></el-table-column>
            <el-table-column prop="passTime" label="通过时间" width="180px" align="center" sortable></el-table-column>
            <el-table-column prop="createTime" label="记录日期" width="180px" align="center" sortable></el-table-column>
            <el-table-column prop="passInOut" label="进出" width="80px" align="center"></el-table-column>
          </el-table>
          <el-footer style="height: 45px; background-color: #fff" class="page-footer">
            <el-pagination style="padding-top: 10px" background layout="prev, pager, next,jumper,total,sizes" @size-change="evtPageSizeChange" @current-change="evtPageCurrentChange" :current-page.sync="currentPage" :page-sizes="[20, 50, 100, 500]" :total="totalRows"></el-pagination>
          </el-footer>
        </div>
      </el-main>
    </el-container>
      <!--导出-->
      <export-excel ref="exportExcel" :sheet-name="sheetName" :file-name="exportFileName"  extend="export" :columns="columns" :rows="totalRows" :query="searchObj" :export-api="exportApi" :isPerSon="false"/>
  </div>
  </el-dialog>
</template>
<script>
import { apiLateRecord } from "@/api/basicData/lateRecord";
import { getPremission } from "@/itsoftUI/auth/permission";
import ToolButton from "@/itsoftUI/components/toolbar/toolbutton";
import exportExcel from "@/itsoftUI/components/exportExcel/recordExportExcel";
export default {
    components: {ToolButton,exportExcel},
    data() {
        return {
        dialogVisible:false,
        loading: false,
        manageCollegeId: "",
        manageBuildingId: "",
        tableData: [],
        manageBuildingList: [],
        manageCollegeList: [],
        dateVal:"",
        loadIng: false,
        currentPage: 1,
        totalRows: 0,
        pageSize: 20,
        order: "passTime desc",
        moduleName:"",
          exportFileName: "",
          sheetName: "",
          searchObj:{},
          exportApi: "",
          columns: [{
            prop: "account",
            label: "学号",
          },{
            prop: "name",
            label: "姓名",
          },{
            prop: "collegeName",
            label: "学院",
          },{
            prop: "className",
            label: "班级",
          },{
            prop: "buildingName",
            label: "楼宇",
          },{
            prop: "roomName",
            label: "房间",
          },{
            prop: "passTime",
            label: "通过时间",
          },{
            prop: "createTime",
            label: "记录日期",
          },{
            prop: "passInOut",
            label: "进出",
          },
          ],
    };
  },
  methods: {
    funGetTabData(){
      if(this.moduleName == "lateIn"){
        this.exportFileName ="晚归记录";
        this.sheetName ="晚归记录";
        this.exportApi =apiLateRecord.getLateReturnRecordList;
            this.getLateReturnRecordList(this.dateVal,this.dateVal)
      }
      if(this.moduleName == "lateOut"){
        this.exportFileName ="晚出记录";
        this.sheetName ="晚出记录";
        this.exportApi =apiLateRecord.getLateNightRecordList;
        this.getLateNightReturnRecordList(this.dateVal,this.dateVal)
      }
      if(this.moduleName == "notBack"){
        this.exportFileName ="未归记录";
        this.sheetName ="未归记录";
        this.exportApi =apiLateRecord.getNotBackRecordList;
        this.getNotBackReturnRecordList(this.dateVal,this.dateVal)
      }
      if(this.moduleName == "preOut"){
        this.exportFileName ="未出预警记录";
        this.sheetName ="未出预警记录";
        this.exportApi =apiLateRecord.getNotOutRecordList;
        this.getPreOutReturnRecordList(this.dateVal,this.dateVal)
      }
      if(this.moduleName == "preIn"){
        this.exportFileName ="未归预警记录";
        this.sheetName ="未归预警记录";
        this.exportApi =apiLateRecord.getNotInRecordList;
        this.getPreInReturnRecordList(this.dateVal,this.dateVal)
      }
    },
    getLateReturnRecordList(startDate, endDate, sortStr) {
      this.loadIng = true;
      let search = [];
      search.push({
        andOr: "and",
        searchField: "createTime",
        operator: ">=",
        searchValue: startDate+" 00:00:00",
      });
      search.push({
        andOr: "and",
        searchField: "createTime",
        operator: "<=",
        searchValue: endDate+" 59:59:59",
      });

      if (this.manageBuildingId) {
        search.push({
          andOr: "and",
          searchField: "buildingId",
          operator: "=",
          searchValue: this.manageBuildingId,
        });
      }
      this.searchObj.search = search;
      this.searchObj.order = sortStr;
      this.searchObj.tag = "lateNightRecord";
      let page = { pageIndex: this.currentPage, pageSize: this.pageSize };
      apiLateRecord.getLateReturnRecordList(JSON.stringify(search),JSON.stringify(page),sortStr).then((res) => {
          if (res.errorCode === 0) {
            res.data.rows.forEach((item) => {
              this.$set(item, "createTime", item.createTime.slice(0, 10));
            });
            this.tableData = res.data.rows;
            this.totalRows = res.data.total;
            this.loadIng = false;
          }
        });
    },
    getLateNightReturnRecordList(startDate, endDate, sortStr) {
      this.loadIng = true;
      let search = [];
      search.push({
        andOr: "and",
        searchField: "createTime",
        operator: ">=",
        searchValue: startDate+" 00:00:00",
      });
      search.push({
        andOr: "and",
        searchField: "createTime",
        operator: "<=",
        searchValue: endDate+" 59:59:59",
      });

      if (this.manageBuildingId) {
        search.push({
          andOr: "and",
          searchField: "buildingId",
          operator: "=",
          searchValue: this.manageBuildingId,
        });
      }
      this.searchObj.search = search;
      this.searchObj.order = sortStr;
      this.searchObj.tag = "lateNightRecord";
      let page = { pageIndex: this.currentPage, pageSize: this.pageSize };
      apiLateRecord.getLateNightRecordList(JSON.stringify(search),JSON.stringify(page),sortStr).then((res) => {
        if (res.errorCode === 0) {
          res.data.rows.forEach((item) => {
            this.$set(item, "createTime", item.createTime.slice(0, 10));
          });
          this.tableData = res.data.rows;
          this.totalRows = res.data.total;
          this.loadIng = false;
        }
      });
    },
    getNotBackReturnRecordList(startDate, endDate, sortStr) {
      this.loadIng = true;
      let search = [];
      search.push({
        andOr: "and",
        searchField: "createTime",
        operator: ">=",
        searchValue: startDate+" 00:00:00",
      });
      search.push({
        andOr: "and",
        searchField: "createTime",
        operator: "<=",
        searchValue: endDate+" 59:59:59",
      });

      if (this.manageBuildingId) {
        search.push({
          andOr: "and",
          searchField: "buildingId",
          operator: "=",
          searchValue: this.manageBuildingId,
        });
      }
      this.searchObj.search = search;
      this.searchObj.order = sortStr;
      this.searchObj.tag = "lateNightRecord";
      let page = { pageIndex: this.currentPage, pageSize: this.pageSize };
      apiLateRecord.getNotBackRecordList(JSON.stringify(search),JSON.stringify(page),sortStr).then((res) => {
        if (res.errorCode === 0) {
          res.data.rows.forEach((item) => {
            this.$set(item, "createTime", item.createTime.slice(0, 10));
          });
          this.tableData = res.data.rows;
          this.totalRows = res.data.total;
          this.loadIng = false;
        }
      });
    },
    getPreOutReturnRecordList(startDate, endDate, sortStr) {
      this.loadIng = true;
      let search = [];
      search.push({
        andOr: "and",
        searchField: "passTime",
        operator: ">=",
        searchValue: startDate+" 00:00:00",
      });
      search.push({
        andOr: "and",
        searchField: "passTime",
        operator: "<=",
        searchValue: endDate+" 59:59:59",
      });

      if (this.manageBuildingId) {
        search.push({
          andOr: "and",
          searchField: "buildingId",
          operator: "=",
          searchValue: this.manageBuildingId,
        });
      }
      this.searchObj.search = search;
      this.searchObj.order = sortStr;
      this.searchObj.tag = "lateNightRecord";
      let page = { pageIndex: this.currentPage, pageSize: this.pageSize };
      apiLateRecord.getNotOutRecordList(JSON.stringify(search),JSON.stringify(page),sortStr).then((res) => {
        if (res.errorCode === 0) {
          this.tableData = res.data.rows;
          this.totalRows = res.data.total;
          this.loadIng = false;
        }
      });
    },
    getPreInReturnRecordList(startDate, endDate, sortStr) {
      this.loadIng = true;
      let search = [];
      search.push({
        andOr: "and",
        searchField: "passTime",
        operator: ">=",
        searchValue: startDate+" 00:00:00",
      });
      search.push({
        andOr: "and",
        searchField: "passTime",
        operator: "<=",
        searchValue: endDate+" 59:59:59",
      });

      if (this.manageBuildingId) {
        search.push({
          andOr: "and",
          searchField: "buildingId",
          operator: "=",
          searchValue: this.manageBuildingId,
        });
      }
      this.searchObj.search = search;
      this.searchObj.order = sortStr;
      this.searchObj.tag = "lateNightRecord";
      let page = { pageIndex: this.currentPage, pageSize: this.pageSize };
      apiLateRecord.getNotInRecordList(JSON.stringify(search),JSON.stringify(page),sortStr).then((res) => {
        if (res.errorCode === 0) {
          this.tableData = res.data.rows;
          this.totalRows = res.data.total;
          this.loadIng = false;
        }
      });
    },
    changeTableSort(column) {
      if (column.order == "ascending") {
        this.order = column.prop + " asc";
        this.getLateReturnRecordList(
          this.dateData[0],
          this.dateData[1],
          column.prop + " asc"
        );
      } else if (column.order == "descending") {
        this.order = column.prop + " desc";
        this.getLateReturnRecordList(
          this.dateData[0],
          this.dateData[1],
          column.prop + " desc"
        );
      }
    },
    evtPageSizeChange(val) {
      //每页数量
      this.pageSize = val;
      this.getLateReturnRecordList(this.dateData[0], this.dateData[1], this.order);
    },
    evtPageCurrentChange(val) {
      //分页
      this.currentPage = val;
      this.getLateReturnRecordList(this.dateData[0], this.dateData[1], this.order);
    },


  },
};
</script>
<style scoped>
.colTitle {
  display: inline-block;
  margin-right: 10px;
  line-height: 34px;
}
</style>
